﻿using System.Text.Json;
using Domain.Repository;
using Domain.Repository.RequestModels;
using Domain.Repository.ResponseModels;
using Infrastructure.RestSharpWrap;
using RestSharp;

namespace Repository.Implements
{
    public class TaskNodeRepository : BaseRepository, ITaskNodeRepository
    {
        public TaskNodeRepository(IRestClientExt restClient) : base(restClient)
        {
        }

        public async Task<MobileGetTaskNodeLstByPageResponseModel> MobileGetTaskNodeLstByPage(MobileGetTaskNodeLstByPageRequestModel model)
        {
            return await Request<MobileGetTaskNodeLstByPageResponseModel, MobileGetTaskNodeLstByPageRequestModel>(
                "MobileGetTaskNodeLstByPage",
                model,
                r => JsonSerializer.Deserialize<MobileGetTaskNodeLstByPageResponseModel>(
                    JsonSerializer.Serialize(r))
                );

            throw new InvalidOperationException("数据获取失败");
        }

        public async Task<TaskNodeGroupResponseModel> MobileGetTaskNodeGroup(MobileGetTaskNodeGroupRequestModel model)
        {
            return await Request<TaskNodeGroupResponseModel, MobileGetTaskNodeGroupRequestModel>(
                "MobileGetTaskNodeGroup",
                model,
                r => JsonSerializer.Deserialize<TaskNodeGroupResponseModel>(
                    JsonSerializer.Serialize(r))
                );

            throw new InvalidOperationException("数据获取失败");
        }
    }
}
